from tools.funciton import *


def switch_shelf(file_name):
    unis = read_xlsx_file(os.path.join(DOWNLOAD_PATH, f'{file_name}.xlsx'), 4)
    news = read_xlsx_file(os.path.join(DOWNLOAD_PATH, f'{file_name}.xlsx'), 7)
    s = 1
    for i in range(len(unis)):
        if jiwu.stocks.find_one({"uniqueCode": unis[i]}) is not None:
            jiwu.stocks.update_one({"uniqueCode": unis[i]}, {"$set": {"shelfCode": news[i]}})
            print('success', s)
            s += 1
        else:
            print('fail')


def switch_file(file_name):
    file = os.path.join(DOWNLOAD_PATH, f'{file_name}.xlsx')
    sks = read_xlsx_file(file, 1)
    arts = [skuId_to_articleNumber(i) for i in sks]
    sizes = [skuId_to_size('jiwu', i) for i in sks]
    update_column_name(file, 'SKUID', '货号')
    update_column_name(file, 'SKU名称', '尺码')
    update_colum_datas(file, '货号', arts)
    update_colum_datas(file, '尺码', sizes)


switch_file('缴款单')
# switch_shelf('缴款单0311')